<template>
    <view class="container">
        <u--form labelPosition="left" labelWidth="90" :model="admin" :rules="rules" ref="uForm">
            <u-form-item label="客户分配" prop="id" borderBottom>
                <u--input v-model="admin.id" border="none" placeholder="请输入用户id"></u--input>
            </u-form-item>
        </u--form>
        <view style="margin-top: 25px;">
            <u-button type="warning" @click="submit">分配</u-button>
        </view>
        <div style="margin-top:1rem;">
            <h3>用户信息</h3>
            <div v-for="item in adminList" :key="item.id">
                <div class="mobile">用户id：{{item.id}};  用户名称：{{item.nickname}}</div>
            </div>
            
            
        </div>
        <u-toast ref="uToast"></u-toast>
    </view>
</template>

<script>
export default {
    data() {
        return {
            id:0,
            admin:{
                id:''
            },
            rules:{
                id: [{
                    required: true,
                    message: '请填用户id',
                    trigger: ['blur', 'change']
                }],
            },
            adminList:[],
            LoginAdmin:uni.getStorageSync('LoginAdmin') ? uni.getStorageSync('LoginAdmin') : {},
        }
    },
    onReady() {
		// 如果需要兼容微信小程序，并且校验规则中含有方法等，只能通过setRules方法设置规则。
    	this.$refs.uForm.setRules(this.rules)
    },
    onLoad(options)
    {
        this.id = options.id;
        this.getDetail();
        // console.log(this.id);
    },
    methods: {
  

        async getDetail()
        {
            let data = {
                    adminid:this.LoginAdmin.id,
                    
                    id:this.id
            }
            let result = await this.$u.api.manage.HighseaAdmin(data);

            this.adminList = result.data;

        },

        async submit(){
            let data = {
                adminid:this.LoginAdmin.id,
                id:this.id,
                admin:this.admin.id
            }

            let result = await this.$u.api.manage.HighseaAllot(data);

            if(result.code === 1)
                {
                    this.$refs.uToast.show({
                        type:'success',
                        message:result.msg,
                        complete:() => {

                            this.$u.route({
                                type:'navigateBack'
                            });

                            return;
                        }
                    })
                }else{
                    this.$refs.uToast.show({
                        type:'error',
                        message:result.msg
                    });

                    return;
                }
        }

    },
    onShow()
    {
        
        // console.log(this.id);
    },
}
</script>


<style>


.mobile{
    font-size: .8rem;
    color: gray;
    border-bottom: 2px solid rgb(170, 169, 169);
    margin-bottom: .5rem;
}

</style>